﻿#include<iostream>
#include<asio.hpp>
using namespace std;
using asio::ip::tcp;

std::string make_daytime_string()
{
	auto t = std::time(nullptr);
	return std::ctime(&t);
}

int main()
{
	try
	{
		//创建服务
		asio::io_service io_service;
		//创建接受器
		tcp::acceptor acceptor(io_service,tcp::endpoint(asio::ip::address_v4::any(),13));
		
		while (true)
		{
			auto new_socket = acceptor.accept();
			new_socket.write_some(asio::buffer(make_daytime_string()));
		}

		//运行服务
		io_service.run();
	}
	catch (const std::exception& e)
	{
		std::cout << "has exception " << e.what() << std::endl;
	}


	return 0;
}